﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

/* ***********************************************
 * Describe:聊天界面入口
 * Author :  MuLongFei
 * Email: 424113771@qq.com
 * DATA: 2017/7/18 16:00:21 
 * FileName: ChatPageManager 
 * Version: V1.0.1
 * ***********************************************/

    class ChatPageManager : MonoBehaviour{

        private Transform root;
        private Button chatBtn;
        private const float msgInterval = 3.0f;
        private float lastClickTime = 0;
        private float nowClickTime = 0;
        private bool allowSendMsg = true;


        private void Start() {
            root = GameObject.Find("Canvas").transform;
            chatBtn = root.FindChild("addNode/GameRoomPage(Clone)/btnGroup/ChatBtn").GetComponent<Button>();
            chatBtn.onClick.AddListener(OnChatBtnClicked);
        }

        private void OnChatBtnClicked() {

            if (GameData.GetInstance().locationIndex != -1)
            {
            if (allowSendMsg)
            {
                TooL.LoadPrefab(root.FindChild("addNode/GameRoomPage(Clone)/FightAddNode").gameObject, "ChatPage").AddComponent<ChatSendMessagePage>();
                allowSendMsg = false;
            }
            else
            {
                //提示
                if (GameObject.Find("MsgHint") == null)
                {
                    GameObject hint = TooL.LoadPrefab(root.FindChild("addNode/GameRoomPage(Clone)/FightAddNode").gameObject, "MsgHint");
                    hint.transform.SetParent(root.FindChild("addNode/GameRoomPage(Clone)/FightAddNode"));
                    hint.transform.localScale *= 1.5F;
                    Destroy(hint, 1.0f);
                }
            }
        }
            else
            {
                Debug.Log("没有坐下不能发送表情！");
                return;
            }
        }

        private void Update()
        {
            lastClickTime += Time.deltaTime;
            if (lastClickTime - msgInterval >= 0)
            {
                allowSendMsg = true;
                lastClickTime = 0;
            }
        }
    }
